refactor(dev): MCP session lifecycles as Effect scoped resources (wave 3.5 stage 3, PR 2) - #159
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 3261b9c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This was referenced Sep 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Subsystem 1 of 4 for #152 stage 3, in the plan's order — MCP sessions first: the lifecycle seam is self-contained behind
McpSessionService/McpSession, giving the smallest blast radius of the four.McpSessionService.#openEffectacquires the epoch lease and plugin-data directory withEffect.acquireReleaseinside the open scope. Releases are infallible (stage-2 lesson): failures are collected, reported through the existing cleanup-failure seam, and the last one re-raises — byte-for-byte the pre-Effect precedence. Once theMcpSessionis constructed it owns the resources and the scope finalizers disarm; a later failure cleans up viasession.close()exactly as before.#assertEpochCurrentEffect(): Effect<void, McpSessionStaleEpochError>probes the pinned epoch before each tool call; the mid-flight-vanish path re-probes and substitutes the typed stale-epoch failure for the incidental abort/timeout, then cancels every in-flight request and closes the session (unchanged contract, including the stderr-overflow mirror).finallychain had. The lifecycle serial queue is now an EffectSemaphore(1).Exit, aggregating into the unchangedMcpSessionServiceCloseErrorfailure order.src/effect/lift.ts: identity-preservingliftPromise/liftTry(typed dev errors and non-Error values must cross the boundary untouched).AbortSignalplumbing (session-service close abort, per-request cancel controllers) intentionally stays at the SDK edge.Parity (all suites unchanged, zero pin flips)
mcp-session-service.test.ts+target-mcp-runtime.test.ts(integration pool): 35 passed / 0 faileddev-server.test.ts,mcp-session-routes.test.ts(AB8018/409 contract), boundary tests (unit pool): 62 passed / 0 failedpnpm lint(incl. boundary rule) +pnpm typecheck: greenRefs #152.